package cn.yunhe.control;

import cn.yunhe.entity.Blank;
import cn.yunhe.entity.Topic;
import cn.yunhe.server.TopicServer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/AccurateSelectTopicByTopicServlet")
public class AccurateSelectTopicByTopicServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String title = request.getParameter("serch"); //获取查询关键字
        String bId = request.getParameter("bId");
        String bName = request.getParameter("bName");

        TopicServer topicServer = new TopicServer();
        Topic topic = new Topic(); //新建帖子对象
        topic.setTitle(title); //补充帖子对象属性

        Blank blank = new Blank(Integer.parseInt(bId),bName); //新建板块对象
        List<Topic> list = topicServer.AccurateSelectTopicByTopic(topic,blank);
        if (list!=null&&list.size()>0){
            request.setAttribute("topicList",list);
            request.getRequestDispatcher("primaryTopic.jsp").forward(request,response);
        }else {
            request.setAttribute("result","没有该标题的帖子信息!!"); //若查询不到结果将提示信息返回前端
            request.getRequestDispatcher("primaryTopic.jsp").forward(request,response);
        }

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
